# -*- coding: utf-8 -*-
# @Time: 2025/4/23 18:16
# @Author: foxhuty
# @File: pytorch_notes_3.py
import torch

# 张量的属性和稀疏张量
dev = torch.device('cuda:0')
a = torch.tensor([2, 2], device=dev, dtype=torch.float32)
print(a)
print(torch.__version__)
print(torch.version.cuda)
print(torch.cuda.is_available())
print(torch.cuda.device_count())
print(torch.cuda.get_device_name(0))
# 稀疏张量和稠密张量的转换
i = torch.tensor([[0, 1, 2], [0, 1, 2]])
v = torch.tensor([1, 2, 3])
a = torch.sparse_coo_tensor(i, v, size=[4, 4],
                            dtype=torch.float32,
                            device=dev).to_dense()
print(a)
